<?php

declare(strict_types=1);

namespace app\controller\admin;

use app\controller\admin\AdminBaseController;
use app\model\admin\SysOperLog as SysOperLogModel;

use think\Request;

class SysOperLog extends AdminBaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index(Request $request)
    {
        $field = "*";
        $data = SysOperLogModel::scope('where', $request->param())
            ->scope('dataFilter')
            ->field($field)
            ->order('id', 'desc')
            ->paginate([
                'list_rows' => $this->limit,
                'page' => $this->page,
                'var_page' => $this->pageVar
            ]);

        return successPage($data);
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete(Request $request)
    {
        $id = $request->param('id', '');
        if (!$id) {
            return error('缺少必要参数');
        }
        $ids = explode(',', $id);

        $ret = SysOperLogModel::destroy($ids);
        if (!$ret) {
            return error('删除失败');
        }
        return success();
    }

    public function clean()
    {
        return error('暂不支持清空');
    }

    public function userOperLog(Request $request)
    {
        return success([]);
        // $field = "*";
        // $ids = [];
        // $params = $request->param();
        // if (isset($params['sys_nickname'])) {
        //     $ids = MemberUser::where('username', 'like', "%{$params['sys_nickname']}%")->column('id');
        // }
        // $data = MemberOperLogModel::with(['user' => function ($q) {
        //     $q->field('id,nickname');
        // }])->where(function ($q) use ($params, $ids) {
        //     if (isset($params['sys_nickname'])) {
        //         $q->whereIn('user_id', $ids);
        //     }
        // })
        //     ->scope('where', $params)
        //     ->field($field)
        //     ->order('id', 'desc')
        //     ->paginate([
        //         'list_rows' => $this->limit,
        //         'page' => $this->page,
        //         'var_page' => $this->pageVar
        //     ]);

        // return successPage($data);
    }
}
